package models

import (
	"time"

	_ "gorm.io/gorm" // 空白导入
)

// 消息状态常量
const (
	MsgStatusPending   = 0
	MsgStatusSent      = 1
	MsgStatusDelivered = 2
	MsgStatusRead      = 3
)

// WsRoomUser 房间成员关系
type WsRoomUser struct {
	RoomID      string    `gorm:"size:64;primaryKey"`
	UserID      string    `gorm:"primaryKey"`
	JoinTime    time.Time `gorm:"autoCreateTime"`
	LastReadAt  time.Time
	UnreadCount int `gorm:"default:0"`
}

// TableName 设置表名
func (WsRoomUser) TableName() string {
	return "ws_room_users"
}

type WsUser struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Avatar string `json:"avatar"`
}

// WsMessage 增强版消息结构
type WsMessage struct {
	MsgID     string    `json:"msg_id"`
	GroupID   string    `json:"group_id"`
	SenderID  string    `json:"sender_id"`
	Sender    string    `json:"sender"`
	Avatar    string    `json:"avatar"`
	Content   string    `json:"content"`
	Event     string    `json:"event"` // "message", "system", etc.
	Timestamp time.Time `json:"timestamp"`
}

// WsChatRecord 增强版聊天记录
type WsChatRecord struct {
	MsgID       string `gorm:"primaryKey"`
	GroupID     string // 改为GroupID
	SenderID    string // 改为string类型
	Content     string
	ContentType int
	Status      int
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

// WsRoom 增强版房间模型
type WsRoom struct {
	RoomID     string    `gorm:"size:64;primaryKey"`
	Name       string    `gorm:"size:128"`
	CreatedBy  uint      `gorm:"index"`
	CreatedAt  time.Time `gorm:"autoCreateTime"`
	LastActive time.Time
}

// WsRoomMember 房间成员
type WsRoomMember struct {
	RoomID      string    `gorm:"size:64;primaryKey"`
	UserID      string    `gorm:"primaryKey"`
	JoinTime    time.Time `gorm:"autoCreateTime"`
	LastReadAt  time.Time
	UnreadCount int `gorm:"default:0"`
}

// WsUserSession 用户连接会话
type WsUserSession struct {
	SessionID   string    `gorm:"size:64;primaryKey"`
	UserID      string    `gorm:"index"`
	DeviceID    string    `gorm:"size:64"`
	IPAddress   string    `gorm:"size:45"`
	ConnectedAt time.Time `gorm:"autoCreateTime"`
	LastPing    time.Time
}

// 兼容腾讯云IM的消息结构
type MsgBody struct {
	MsgType    string     `json:"MsgType"`
	MsgContent MsgContent `json:"MsgContent"`
}

type MsgContent struct {
	Data string `json:"Data"`
}
